/*
 * Copyright (c) 2018. , apexes.net. All rights reserved.
 *
 *         http://www.apexes.net
 *
 */
package net.apexes.wsonrpc.client;

import net.apexes.wsonrpc.core.WebSocketSession;
import net.apexes.wsonrpc.core.WsonrpcEngine;
import net.apexes.wsonrpc.json.JsonRpcRequest;

import java.util.concurrent.Executor;

/**
 * @author hedyn
 */
class WsonrpcClientEngine extends WsonrpcEngine {

    private final Executor executor;

    WsonrpcClientEngine(WsonrpcClientConfig config) {
        super(config);
        executor = config.getExecutor();
    }

    Executor getExecutor() {
        return executor;
    }

    @Override
    protected void handleRequest(final WebSocketSession session, final JsonRpcRequest request) {
        if (executor != null && request != null) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    execReply(session, request);
                }
            });
        } else {
            execReply(session, request);
        }
    }

    private void execReply(WebSocketSession session, JsonRpcRequest request) {
        super.handleRequest(session, request);
    }
}
